home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / sendpkt.c < prev    next >
C/C++ Source or Header  |  1989-09-16  |  2KB  |  60 lines

  1. /* From: ConPackets.c -  C. Scheppner, A. Finkel, P. Lindsay  CBM
  2.  *   DOS packet example
  3.  *   Requires 1.2
  4.  * 
  5.  */
  6. #include <exec/types.h>
  7. #include <exec/ports.h>
  8. #include <exec/memory.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13.  
  14. LONG sendpkt(struct MsgPort *, LONG, LONG *, LONG);
  15.  
  16. LONG sendpkt(pid,action,args,nargs)
  17. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  18. LONG action,          /* packet type ... (what you want handler to do )   */
  19.      args[],          /* a pointer to a argument list */
  20.      nargs;           /* number of arguments in list  */
  21.    {
  22.    struct MsgPort        *replyport;
  23.    struct StandardPacket *packet;
  24.  
  25.    LONG  count, *pargs, res1;
  26.  
  27.    replyport = (struct MsgPort *) CreatePort(NULL,0);
  28.    if(!replyport) return(NULL);
  29.  
  30.    packet = (struct StandardPacket *) 
  31.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  32.    if(!packet) 
  33.       {
  34.       DeletePort(replyport);
  35.       return(NULL);
  36.       }
  37.  
  38.    packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  39.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  40.    packet->sp_Pkt.dp_Port         = replyport;
  41.    packet->sp_Pkt.dp_Type         = action;
  42.  
  43.    /* copy the args into the packet */
  44.    pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  45.    for(count=0;count < nargs;count++) 
  46.       pargs[count]=args[count];
  47.  
  48.    PutMsg(pid,(struct Message *)packet); /* send packet */
  49.  
  50.    WaitPort(replyport);
  51.    GetMsg(replyport); 
  52.  
  53.    res1 = packet->sp_Pkt.dp_Res1;
  54.  
  55.    FreeMem((char *)packet,(long)sizeof(struct StandardPacket));
  56.    DeletePort(replyport); 
  57.  
  58.    return(res1);
  59. }
  60.